<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <%@ include file="/common/plateform/include/common-base.jsp" %>
    <title>动态表单-字段设计器</title>
</head>
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">

    <!-- top start -->
    <%@include file="/common/plateform/top.jsp" %>
    <!-- top end -->

    <!-- left start -->
    <%@include file="/common/plateform/left-project.jsp" %>
    <!-- left end-->

    <!-- Main start -->
    <div class="content-wrapper">
        <!-- Main start -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12 ibox">

                    <!--搜索  start -->
                    <div class="box box-info collapsed-box">

                        <!--搜索title  start    -->
                        <div class="box-header with-border">
                            <h3 class="box-title"><i class="fa fa-search"></i> 字段搜索</h3>
                            <div class="box-tools pull-right">
                                <button type="button" class="btn btn-box-tool"
                                        data-widget="collapse"><i class="fa fa-plus"></i></button>
                                <button type="button" class="btn btn-box-tool" data-widget="remove">
                                    <i class="fa fa-times"></i></button>
                            </div>
                        </div>

                        <!--搜索title  end -->
                        <div class="box-body">
                            <form id="searchForm" class="form-horizontal">
                                <input type="hidden" name="pageName" value="objName-table-column"/>
                                <input type="hidden" name="formName" value="searchForm"/>
                                <c:if test="${empty database_type || database_type=='oracle'}">
                                    <input type="hidden" name="orderBy"
                                           value="to_number(metadata.reserved1),metadata.data_attr"/>
                                </c:if>
                                <c:if test="${not empty database_type && database_type=='mysql'}">
                                    <input type="hidden" name="orderBy"
                                           value="cast(metadata.reserved1 as unsigned int),metadata.data_attr"/>
                                </c:if>
                                <input type="hidden" name="metadata.w_sortId" value="${param.sortId}"/>
                                <div class="form-group">
                                    <div class="col-sm-2 text-right"><label class="control-label">字段英文名：</label>
                                    </div>
                                    <div class="col-sm-4">
                                        <input type="text" class="form-control clean"
                                               name="metadata.wl_dataShortName" value=""/>
                                    </div>
                                    <div class="col-sm-2 text-right"><label class="control-label">字段属性名：</label>
                                    </div>
                                    <div class="col-sm-4">
                                        <input type="text" class="form-control clean"
                                               name="metadata.wl_dataAttr" value=""/>
                                    </div>
                                </div>
                                <center>
                                    <div class="box-footer clearfix">
                                        <button type="button" class="btn btn-success"
                                                onclick="getTableData();"><i
                                                class="fa fa-search"></i> 查询
                                        </button>&nbsp;
                                        <button type="button" class="btn btn-warning"
                                                onclick="mytools.cleanData('#searchForm');">重置
                                        </button>
                                    </div>
                                </center>
                            </form>
                        </div>
                    </div>
                    <!-- 搜索 end -->


                    <div class="box box-success">
                        <!--列表title  start -->
                        <div class="box-header with-border">
                            <h3 class="box-title">
                                <i class="fa fa-table"
                                   onclick="javascript:void('-1')"></i> ${param.tableName}表字段管理&nbsp;
                                <c:if test="${fn:indexOf(IusPlateStr,param.tableName)==-1}">
                                    <button onclick="toAdd();" class="btn btn-success" type="button"><i
                                            class="fa fa-plus-circle"></i> 增加字段
                                    </button>
                                </c:if>
                                <c:if test="${fn:indexOf(IusPlateStr,param.tableName)>-1 && loginUser.delStatus=='1'}">
                                    <button onclick="toAdd();" class="btn btn-success" type="button"><i
                                            class="fa fa-plus-circle"></i> 增加字段
                                    </button>
                                </c:if>
                                <button onclick="toBack('${page_admin}/project/objName-table2');"
                                        class="btn btn-primary" type="button"><i
                                        class="fa fa-reply"></i> 返回
                                </button>
                            </h3>
                            <div class="box-tools pull-right">
                                　　　　　　　　
                            </div>
                        </div>

                        <!-- /.box-header -->
                        <div class="box-body">
                            <table id="dataList" class="table table-bordered table-hover">
                                <thead class="bg-success">
                                <tr>
                                    <th rowspan="2" style="vertical-align: middle">序号</th>
                                    <th colspan="5" class="text-center">字段基本属性</th>
                                    <th colspan="5" class="text-center">表单属性</th>
                                    <th rowspan="2" style="text-align: center;vertical-align: middle">操作</th>
                                </tr>
                                <tr>
                                    <th>字段名</th>
                                    <th>中文名</th>
                                    <th>字段类型</th>
                                    <th>字段约束</th>
                                    <th>字段属性</th>
                                    <th>控件类型</th>
                                    <th>表格显示</th>
                                    <th>是否为空</th>
                                    <th>字典名称</th>
                                    <th>默认值</th>
                                </tr>
                                </thead>
                                <tbody id="dataList-body">
                                </tbody>
                            </table>
                            <center>
                                <ul id="dataList-page"></ul>
                            </center>
                        </div>

                    </div>
                </div>
            </div>


            <div class="modal fade" id="my_modal" role="dialog" aria-labelledby="myModalLabel"
                 aria-hidden="true">
                <div class="modal-dialog" style="width:900px;">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal"
                                    aria-hidden="true">
                                &times;
                            </button>
                            <h4 class="modal-title red">
                                <font id="span_submitForm_title">添加/修改</font>字段操作&nbsp;
                            </h4>
                        </div>
                        <div class="modal-body">

                            <form class="form-horizontal" role="form" id="submitForm" action="javascript:;">

                                <!-- 隐藏域 start -->
                                <input type="hidden" name="formToken" class="formToken" id="submitForm_formToken" value=""/>
                                <input type="hidden" id="w_metadataId" data-name="metadata.metadataId" name="metadataId" value=""/>
                                <input type="hidden" name="sortId" value="${param.sortId}"/>
                                <input type="hidden" name="sysName" value=""/>
                                <!-- 隐藏域 end -->

                                <div class="box-body" id="submitFormData">

                                    <input type="hidden" name="fieldConf" class="clean" data-name="metadata.fieldConf"/>

                                    <!-- 属性循环体 start -->
                                    <div class="form-group">
                                        <div class="col-sm-12 bg-success">基本配置</div>
                                    </div>
                                    <table class="table table-bordered">
                                        <tbody>
                                            <tr>
                                                <td class="text-right">
                                                    <label class="control-label"><font
                                                            color="red">*</font>字段英文名</label>
                                                </td>
                                                <td>
                                                    <div class="form-group">
                                                        <input type="text" id="dataShortName"
                                                               name="dataShortName"  data-name="metadata.dataShortName"
                                                               onchange="setdataShortName()"
                                                               class="form-control clean" maxlength="50"
                                                               placeholder="只能小写字母、数字、下划线组合">
                                                    </div>
                                                </td>
                                                <td class="text-right">
                                                    <label class="control-label"><font
                                                            color="red">*</font>字段中文名</label>
                                                </td>
                                                <td>
                                                    <div class="form-group">
                                                        <input type="text" id="dataFullName" name="dataFullName"
                                                               class="form-control clean" maxlength="30" data-name="metadata.dataFullName"
                                                               placeholder="输入中文描述"/>
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="text-right">
                                                    <label class="control-label"><font
                                                            color="red">*</font>字段属性名</label>
                                                </td>
                                                <td>
                                                    <div class="form-group">
                                                        <input type="text" id="dataAttr" name="dataAttr" data-name="metadata.dataAttr"
                                                               class="form-control clean" maxlength="50"
                                                               placeholder="驼峰规则，如字段[us_sex]写[usSex]">
                                                    </div>
                                                </td>
                                                <td class="text-right">
                                                    <label class="control-label"><font
                                                            color="red">*</font>字段约束</label>
                                                </td>
                                                <td>
                                                    <div class="form-group">
                                                        <select id="dataRestrict" name="dataRestrict" data-name="metadata.dataRestrict"
                                                                class="form-control">
                                                            <option value="3" selected="selected">可空</option>
                                                            <option value="1">主键</option>
                                                            <option value="2">非空</option>
                                                            <option value="4">联合主键</option>
                                                        </select>
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="text-right">
                                                    <label class="control-label"><font
                                                            color="red">*</font>数据类型</label>
                                                </td>
                                                <td>
                                                    <div class="form-group">
                                                        <select name="dataType" id="dataType" data-name="metadata.dataType"
                                                                class="form-control">
                                                            <option value="5" selected="selected">字符-varchar（推荐）</option>
                                                            <option value="2">长整型-bigint/number</option>
                                                            <option value="3">小数-float</option>
                                                            <option value="1">整型-int</option>
                                                            <option value="6">日期-datetime/date</option>
                                                            <option value="4">字节-char</option>
                                                        </select>
                                                    </div>
                                                </td>
                                                <td class="text-right">
                                                    <label class="control-label"><font
                                                            color="red">*</font>数据长度</label>
                                                </td>
                                                <td>
                                                    <div class="form-group">
                                                        <input type="text" data-name="metadata.dataLength"
                                                               id="dataLength" name="dataLength"
                                                               class="form-control" maxlength="10" value="50"
                                                               placeholder="必须是数字"/>
                                                    </div>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>

                                    <div class="form-group hidden">
                                        <label class="col-sm-2 control-label">字段顺序</label>
                                        <div class="col-sm-4">
                                            <input type="text" name="reserved1" readonly="readonly" id="reserved1"
                                                   class="form-control clean" maxlength="6" data-name="metadata.reserved1"
                                                   placeholder="可空，但必须是数字"/>
                                        </div>
                                        <label class="col-sm-2 control-label">是否实体字段</label>
                                        <div class="col-sm-4">
                                            <select name="reserved2" id="reserved2" data-name="metadata.reserved2"
                                                    class="form-control">
                                                <option value="T" selected="selected">是</option>
                                                <option value="F">否</option>
                                            </select>
                                            <div class="f12 red"><i class="fa fa-info-circle"></i>
                                                当虚拟字段时才选择【否】
                                            </div>
                                        </div>
                                    </div>


                                    <div class="">
                                        <div class="form-group">
                                            <div class="col-sm-12 bg-success">表单配置<span class="f10">（结合实际需求选择性设置相关配置项）</span> </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">表格显示</label>
                                            <div class="col-sm-4">
                                                <select name="ifList" id="ifList" data-name="metadata.ifList"
                                                        class="form-control clean">
                                                    <option value="">--请选择--</option>
                                                    <option value="T">是</option>
                                                    <option value="F" selected="selected">否</option>
                                                </select>
                                            </div>
                                            <label class="col-sm-2 control-label">控件类型</label>
                                            <div class="col-sm-4">
                                                <select id="colmunType" data-name="metadata.colmunType"
                                                        onchange="changeColmunType(this)"
                                                        name="colmunType" class="form-control">
                                                    <option value="input" selected="selected">
                                                        input-输入框
                                                    </option>
                                                    <option value="inputHidden">input-隐藏域</option>
                                                    <option value="radio">radio-单选</option>
                                                    <option value="checkbox">checkbox-多选（未开放）
                                                    </option>
                                                    <option value="select">select-下拉列表</option>
                                                    <option value="textarea">textarea-文本域</option>
                                                    <option value="date">date-日期文本框</option>
                                                    <option value="uploadimg">uploadimg-上传图片
                                                    </option>
                                                </select>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">是否为空</label>
                                            <div class="col-sm-4">
                                                <select field-conf="true" name="ifNull" id="ifNull"
                                                        class="form-control clean">
                                                    <option value="">--请选择--</option>
                                                    <option value="T">是</option>
                                                    <option value="F" selected="selected">否</option>
                                                </select>
                                            </div>
                                            <label class="col-sm-2 control-label">默认值</label>
                                            <div class="col-sm-4">
                                                <input field-conf="true" type="text" id="defVal" name="defVal"
                                                       class="form-control clean" maxlength="50"
                                                       placeholder=""/>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">字典名称</label>
                                            <div class="col-sm-4">
                                                <input field-conf="true" type="text" id="dictCode" name="dictCode"
                                                       class="form-control clean" maxlength="100"
                                                       placeholder="填写所需的数据字典标识"/>
                                            </div>
                                        </div>


                                        <!--
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">请求URL</label>
                                            <div class="col-sm-10">
                                                <input type="text" id="reqUrl" name="reqUrl"
                                                       maxlength="200" class="form-control  clean"
                                                       placeholder="输入类型是 radio、checkbox、select 时必填"/>
                                                <div style="font-size:11px;color:red;">
                                                    案例1：doCode=dictItemList&cateEname=userType
                                                    ,案例2：doCode=dymicSql&modelTypes=s_trpCate
                                                </div>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">反显列</label>
                                            <div class="col-sm-10">
                                                <input type="text" id="resColmun" name="resColmun"
                                                       class="form-control clean" maxlength="100"
                                                       placeholder="请求URL参数涵 doCode=dymicSql 时必填"/>
                                                <div style="font-size:11px;color:red;">
                                                    案例1：为空或{value:'itemValue',text:'itemText'}
                                                    ,案例2：{value:'cateId',text:'cateName',other:'cateNo,cateType'}
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">

                                    </div>
                                    -->

                                </div>

                                <div class="box-footer">
                                    <button type="button" class="btn btn-success pull-left"
                                            onclick="mytools.closeModal('my_modal');">取消
                                    </button>
                                    <button type="button" class="btn btn-danger pull-right"
                                            onclick="saveInfo('submitForm');">提 交
                                    </button>
                                </div>

                            </form>
                        </div>
                    </div>
                    <!-- /.modal-content -->
                </div>
            </div>

            <div win-title="查看窗口" class="modal fade" id="my_modal_view" tabindex="-2" role="dialog"
                 aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog" style="width:900px;">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal"
                                    aria-hidden="true">
                                &times;
                            </button>
                            <h4 class="modal-title">
                                <font color="red">查看详情</font>&nbsp;
                            </h4>
                        </div>
                        <div class="modal-body">

                        </div>
                    </div>
                    <!-- /.modal-content -->
                </div>
            </div>

            <script type="text/template" id="dataList-template">
                <? for ( var i = 0; i < rows.length; i++) {?>
                <tr field-conf="<?=rows[i].metadata.fieldConf?>">
                    <td><?=(pageObj.currentPage-1)*10+(i+1)?></td>
                    <td><?=strUtil.doNull(rows[i].metadata.dataShortName,'')?></td>
                    <td title="<?=rows[i].metadata.dataFullName?>"><?=strUtil.subStr(rows[i].metadata.dataFullName,5)?></td>
                    <td><?=getColumType(rows[i].metadata.dataType,rows[i].metadata.dataLength)?></td>
                    <td><?=dataRestrictTxt(rows[i].metadata.dataRestrict)?></td>
                    <td><?=strUtil.doNull(rows[i].metadata.dataAttr,'')?></td>
                    <td><?=rows[i].metadata.colmunType?></td>
                    <td><?=checkedTxt(rows[i].metadata.ifList)?></td>
                    <td field-name="ifNull" field-format="checkedTxt"></td>
                    <td field-name="dictCode"></td>
                    <td field-name="defVal"></td>
                    <td>
                        <button type="button" class="btn btn-success btn-xs"
                                onclick="toLoad('<?=rows[i].metadata.metadataId?>','edit')">修改
                        </button> &nbsp;&nbsp;
                        <?if(rows[i].metadata.dataRestrict==1 || rows[i].metadata.dataRestrict==4){?>
                        <span class='fx8 f10'>不可删</span>
                        <?}else{?>
                        <button type="button" class="btn btn-danger btn-xs"
                                onclick="toDele('<?=rows[i].metadata.metadataId?>','<?=rows[i].metadata.sortId?>','<?=rows[i].metadata.dataFullName?>','<?=rows[i].metadata.dataShortName?>')">
                            删除
                        </button>
                        <?}?>
                    </td>
                </tr>
                <?}?>
            </script>

            <script>
                var clickMenu = "objName-table2";
                var id, myPage, dataListId, searchFormId, isShowLog, objName, objId;
                myPage = 10;
                dataListId = "dataList";
                searchFormId = "searchForm";
                objName = "metadata";
                objId = "metadataId";
                isShowLog = true;
                var totalCounts = 0;
                var defSysEname = strUtil.doNull(strUtil.getLocalStorage("sysEname"), "");
                $("#submitForm").find("input[name='sysName']").val(defSysEname);
                var databaseTypeNow = strUtil.doNull("${database_type}", 'mysql');
                $(function () {
                    //1、加载分页列表数据
                    getTableData();
                    //2、控制是否启用token
                    //setToken();

                });

                function getColumType(t, len) {
                    if ("mysql" == databaseTypeNow) {
                        if ("1" == t) return "int";
                        if ("2" == t) return "bigint";
                        if ("3" == t) return "float(" + len + ",6)";
                        if ("4" == t) return "char(" + len + ")";
                        if ("5" == t) return "varchar(" + len + ")";
                        if ("6" == t) return "datetime";
                    } else {
                        var ctypeMap = {};
                        ctypeMap["1"] = "number";
                        ctypeMap["2"] = "long";
                        ctypeMap["3"] = "double";
                        ctypeMap["4"] = "char";
                        ctypeMap["5"] = "varchar2";
                        ctypeMap["6"] = "date";
                        return ctypeMap[t] + "(" + len + ")";
                    }
                }
                function checkedTxt(v) {
                    if (v == "T") {
                        return "是";
                    } else if (v == "F") {
                        return "否";
                    } else {
                        return "";
                    }
                }

                //加载列表数据
                function getTableData() {
                    //alert(arguments[0]);
                    $.ajax({
                        type: 'get',
                        url: common_list_url,
                        data: $("#" + searchFormId).serialize() + getCurrentPage(common_list_url + "?" + $("#" + searchFormId).serialize(), myPage),
                        dataType: 'json',
                        success: function (myData) {
                            console.log(myData);
                            totalCounts = myData.total;
                            var data = baidu.template(dataListId + "-template", eval(myData));
                            $("#" + dataListId + "-body").html(data);
                            //单独处理json格式的解析，与td定义字段对应
                            handFieldConf("#" + dataListId + "-body");
                            var option = {
                                ele: $("#" + dataListId + "-page")[0],
                                total: myData.total,
                                fn: getTableData,
                                url: common_list_url + "?" + $("#" + searchFormId).serialize()
                            }
                            generatePages(option);
                        }
                    });
                }

                //单独处理json格式的解析，与td定义字段对应
                function handFieldConf(tableId) {
                    $(tableId).find("tr[field-conf]").each(function () {
                        var confMapStr = $(this).attr("field-conf");
                        if(!strUtil.isNull(confMapStr)){
                            var confMap = JSON.parse(confMapStr);
                            for(var fieldKey in confMap){
                                var fieldVal = confMap[fieldKey];
                                var fieldObj = $(this).find("td[field-name='"+fieldKey+"']");
                                var funName = fieldObj.attr("field-format");
                                if(!strUtil.isNull(funName)){
                                    try{
                                        fieldVal=window[funName](fieldVal);
                                    }catch (e) {}
                                }
                                fieldObj.text(fieldVal);
                            }
                        }
                    });
                }

                //打开添加页面
                function toAdd() {
                    mytools.cleanData("submitFormData");//清空模态窗口内数据
                    $("#span_submitForm_title").text("增加");
                    $("#dataRestrict").val("3");
                    $("#dataType").val("5");
                    $("#dataLength").val("50");
                    $("#colmunType").val("input");
                    doAdd("my_modal");
                }

                //读取（查询、编辑）数据
                function toLoad(id, type) {
                    var paramLoadData = {"metadata.w_metadataId": id, "pageName": "objName-table-column","formName":"searchForm"};
                    loadObj(type, paramLoadData);
                }

                //拼装页面配置json格式
                function addFieldConf() {
                    var confMap = {};
                    $("[field-conf='true']").each(function () {
                        var fieldKey = $(this).attr("name");
                        var fieldVal = $(this).val();
                        confMap[fieldKey]=fieldVal;
                    });
                    var confMapStr = JSON.stringify(confMap);
                    console.log("confMap",confMap);
                    $("#submitForm").find("input[name='fieldConf']").val(confMapStr);
                }
                /**
                 * 表单数据提交
                 * @param formId
                 */
                function saveInfo(formId) {
                    var tableName = "${param.tableName}";
                    tableName = transformStr3(tableName);
                    var colName = $("#dataShortName").val();
                    var attrName = tableName + "." + colName;
                    var maxLength = 30;//默认按照oracle的最大列长度
                    if ("${database_type}" == "mysql") {
                        maxLength = 40;
                    }
                    if (attrName.length > parseInt(maxLength)) {
                        layer.tips("设计字段时,【实体.字段名】不能超过【" + maxLength + "】个字符！尽量使用简写。","#dataShortName",{tips:3});
                        return;
                    }
                    var dataShortNameObj = $("#dataShortName");
                    if (strUtil.isNull(dataShortNameObj.val())) {
                        layer.tips("字段英文名称不能为空！","#"+dataShortNameObj.attr("id"),{tips:3});
                        return;
                    }
                    var dataFullNameObj = $("#dataFullName");
                    if (strUtil.isNull(dataFullNameObj.val())) {
                        layer.tips("字段中文描述不能为空！","#"+dataFullNameObj.attr("id"),{tips:3});
                        return;
                    }
                    var dataAttrObj = $("#dataAttr");
                    if (strUtil.isNull(dataAttrObj.val())) {
                        layer.tips("属性名称不能为空！","#"+dataAttrObj.attr("id"),{tips:3});
                        return;
                    }
                    var dataLengthObj = $("#dataLength");
                    if (strUtil.isNull(dataLengthObj.val())) {
                        layer.tips("数据长度不能为空！","#"+dataLengthObj.attr("id"),{tips:3});
                        return;
                    }
                    var dataTypeObj = $("#dataType");
                    if("5"!=dataTypeObj.val() && parseInt(dataLengthObj.val())>255){
                        layer.tips("选择了非字符数据类型时，长度不能超过255！","#"+dataLengthObj.attr("id"),{tips:3});
                        return;
                    }
                    addFieldConf();
                    var index_submit = layer.confirm('您确定要提交字段['+dataShortNameObj.val()+']操作吗？', {
                            btn: ['Yes', 'No'],
                            closeBtn: 0,
                            offset: '220px'
                        }
                        , function () {
                            layer.close(index_submit);
                            var index_load = layer.load(1, {shade: false});
                            $.ajax({
                                type: "post",
                                url: "${ctx}/info/saveMetadata",
                                data: $("#" + formId).serialize(),
                                dataType: "json",
                                success: function (myData) {
                                    layer.close(index_load);
                                    //console.log(myData);
                                    if (myData.flag == "T") {
                                        layer.alert("数据操作成功");
                                        $("#my_modal").modal("hide");
                                    } else {
                                        layer.alert(myData.msg);
                                    }
                                    getTableData();
                                }
                            });
                        });
                }

                function checkColNameIsExist(colName) {
                    var flag = false;
                    var sortId = $("#" + searchFormId).find("input[name='metadata.w_sortId']").val();
                    var paramData={"metadata.w_dataShortName":colName,"metadata.w_sortId":sortId,"pageName":"objName-table-column","formName":"searchForm"};
                    var metadataId=$("#submitForm").find("input[name='metadataId']").val();
                    $.ajax({
                        type: 'get',
                        url: common_list_url,
                        data: paramData,
                        dataType: 'json',
                        async:false,
                        success: function (myData) {
                            console.log(myData);
                            if(myData.total>0){
                                var objData = myData.metadata;
                                var hisMetadataId = objData.metadataId;
                                if(!strUtil.isNull(metadataId) && hisMetadataId==metadataId){
                                    //修改时若是自己则认为不重复
                                    flag=false;
                                }else{
                                    flag=true;
                                }
                            }
                        }
                    });
                    return flag;
                }
                //反显数据
                function showData(type, myData) {
                    console.log(myData);
                    if ("view" == type) {
                        FormUtil.loadView("", myData);

                        doView("my_modal_view");
                    } else if ("edit" == type) {
                        //FormUtil.loadView(objName, myData);
                        mytools.cleanData("#submitFormData");
                        var objData = myData.metadata;
                        DictUtil.checkSelectDict("#reserved2", objData.reserved2);
                        $("#colmunType").val("input");
                        FormUtil.loadView("metadata",objData);
                        doEdit("my_modal", objData);
                    }
                }


                function dataRestrictTxt(v) {
                    if (v == "1") return "主键";
                    else if (v == "2") return "非空";
                    else if (v == "3") return "可空";
                    else if (v == "4") return "联合主键";
                    else v;
                }

                //逻辑删除
                function toDele(id, sortId, fname, cname) {
                    //alert(id+"--"+sortId);
                    var index_submit = layer.confirm("确定删除字段：[" + fname + "-" + cname + "]吗？", {
                            btn: ['Yes', 'No'],
                            closeBtn: 0,
                            offset: '220px'
                        }
                        , function () {
                            layer.close(index_submit);
                            var paramData = {"metadataId": id, sortId: sortId};
                            $.ajax({
                                type: "get",
                                url: "${ctx}/info/delMetadata",
                                data: paramData,
                                dataType: "json",
                                success: function (myData) {
                                    console.log(myData);
                                    var result = myData.flag;
                                    if (result == "T") {
                                        //layer.alert("删除操作成功");
                                        refresh();
                                    }
                                }
                            });
                        });
                }

                function setdataShortName() {
                    var dataShortName = $("#dataShortName").val();
                    if (/^[a-z][a-z0-9_]*$/.test(dataShortName)) {
                        $("#dataAttr").val(transformStr3(dataShortName));
                    } else {
                        layer.tips('只能小写字母、数字、下划线组合，且开头必须是字母', '#dataShortName', {tips: 3});
                        $("#dataShortName").val("");
                        return;
                    }
                    var flag = checkColNameIsExist(dataShortName);
                    if(flag){
                        layer.tips('此['+dataShortName+']字段已存在，请更换！', '#dataShortName', {tips: 3});
                        $("#dataShortName").val("");
                        $("#dataAttr").val("");
                        return;
                    }

                }

                //字符串转成驼峰的方法
                function transformStr3(str) {
                    var re = /_(\w)/g;
                    return str.replace(re, function ($0, $1) {
                        return $1.toUpperCase();
                    });
                }


                //设置模态框隐藏事件
                $('#my_modal').on('show.bs.modal', function (e) {
                    $.ajax({
                        type: 'get',
                        url: ctx + '/sendPage/token?token=true',
                        dataType: 'json',
                        success: function (myData) {
                            if (isShowLog) console.log(myData);
                            $('.formToken').val(myData);
                        }
                    });
                });

                $("select[name='dataRestrict']").change(function () {
                    var thisVal = $(this).val();
                    //alert(thisVal);
                    if("1"==thisVal||"4"==thisVal){
                        var paramData={};
                        paramData["pageName"]="objName-table";
                        paramData["formName"]="searchForm";
                        paramData["sortInfo.w_sortId"]="${param.sortId}";
                        $.ajax({
                            type: 'get',
                            url:common_info_url,
                            data: paramData,
                            async: false,
                            dataType: 'json',
                            success: function (myData) {
                                console.log("sortInfo",myData);
                                if(myData && "1"==myData.sortInfo.sortStatus){
                                    layer.msg("该表是“启用”状态，故不能设置字段类型为主键或联合主键！");
                                    $("#dataRestrict").val("3");
                                    return;
                                }
                            }
                        });
                    }
                });

                //打开添加页面
                function doAdd(modalId) {
                    $("#w_" + objId).val("");
                    $("#modelTypes").val("i_" + objName);
                    $("#" + modalId).modal('show');

                    mytools.cleanData("#submitFormData");//清空表单元素上次填写的内容；
                    //setValidate("#submitFormData");//定义add表单验证属性
                    //mytools.cleanValidate("#submitFormData");//清空上次校验规则提示

                    $("#reserved1").val((totalCounts + 1));
                    $("#dataRestrict").val(3);
                }

                //打开修改页面
                function doEdit(modalId, objData) {
                    var id = objData.metadataId;
                    $("#modelTypes").val("u_" + objName);
                    $("#w_" + objId).val(id);
                    $("#" + modalId).modal("show");
                    $("#span_submitForm_title").text("修改");

                    //页面配置json字符串反显至到相关表单上
                    var confMapStr = $("#submitForm").find("input[name='fieldConf']").val();
                    if(!strUtil.isNull(confMapStr)){
                        var confMap = JSON.parse(confMapStr);
                        $("[field-conf='true']").each(function () {
                            var fieldKey = $(this).attr("name");
                            for(var fielName in confMap){
                                if(fieldKey==fielName){
                                    $(this).val(confMap[fieldKey]);
                                }
                            }
                        });
                    }
                }

                //打开查看页面
                function doView(modalId) {
                    $("#" + modalId).modal("show");
                }

                //获取对象值
                function loadObj(type, paramData) {
                    $.ajax({
                        type: 'get',
                        url: common_info_url,
                        data: paramData,
                        async: false,
                        dataType: "json",
                        success: function (myData) {
                            showData(type, myData);
                        }
                    });
                }

                //删除信息（逻辑删除）
                function doDele(paramData) {
                    $.ajax({
                        type: "post",
                        url: common_submit_url ,
                        data: paramData,
                        dataType: "json",
                        success: function (myData) {
                            var result = myData.flag;
                            if (result == "T") {
                                layer.alert("删除操作成功");
                                refresh();
                            }
                        }
                    });
                }

                /**
                 * 表单数据提交
                 * @param formId
                 */
                function save(formId) {
                    var index_submit = layer.confirm('您确定要提交信息吗？', {
                            btn: ['Yes', 'No'],
                            closeBtn: 0,
                            offset: '220px'
                        }
                        , function () {
                            layer.close(index_submit);
                            $.ajax({
                                type: "post",
                                url: common_submit_url,
                                data: $("#" + formId).serialize(),
                                dataType: "json",
                                success: function (myData) {
                                    //console.log(myData);
                                    if (myData.flag == "T") {
                                        layer.alert("数据保存成功");
                                        $("#my_modal").modal("hide");
                                    } else {
                                        layer.alert(myData.msg);
                                    }
                                    refresh();
                                }
                            });
                        });
                }

                function refresh() {
                    getTableData();
                }


                function setToken() {
                    $.ajax({
                        type: 'get',
                        url: ctx + '/sendPage/token?token=true',
                        dataType: 'text',
                        success: function (myData) {
                            console.log(myData);
                            $('.formToken').val(myData);
                        }
                    });
                }

                function toBack(url) {
                    var page = "${param.page}";
                    if (page) {
                        sessionStorage.setItem("page", page);
                    }
                    mytools.pjax(url);
                }
            </script>
        </section>
        <!-- Main end -->
    </div>
    <!-- /.content-wrapper -->
    <!-- foot start -->
    <%@include file="/common/plateform/foot.jsp" %>
    <!-- foot start -->

</div>


</body>


</html>

